package host.skiree.nettydemo;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;

/**
 * @author gcl
 * @date 2022/9/6 10:02
 */
@Slf4j
@SpringBootTest
public class NettyDemo {

    @Autowired
    static
    JdbcTemplate jdbcTemplate;


    public static void main(String[] args) {
        Task runnable0 = new Task("Thread - 0");
        Task runnable1 = new Task("Thread - 1");
        Task runnable2 = new Task("Thread - 2");
        Task runnable3 = new Task("Thread - 3");
        Thread thread0 = new Thread(runnable0);
        Thread thread1 = new Thread(runnable1);
        Thread thread2 = new Thread(runnable2);
        Thread thread3 = new Thread(runnable3);
        thread0.start();
        thread1.start();
        thread2.start();
        thread3.start();
    }

    static class Task implements Runnable{
        private String name;
        public Task(String name){
            this.name = name;
        }
        @Override
        public void run() {
            System.out.printf("线程 {} 启动",name);
            while (true){
                for (int i = 1; i < 10000001; i++) {
                    jdbcTemplate.execute("INSERT INTO `data`.`data`(`name`, `birth`) VALUES ('" + RandomUtil.genChineseName()  +"', '"+RandomUtil.genLocalDate("1949-10-1", "2022-9-7")+"');");
                }
            }
        }
    }


}
